<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>

<form:form id="cusUserForm" commandName="model" cssClass="validate"
	action="app/user/saveBaseInfo">
	<form:hidden path="id" />
    <form:hidden path="areCustomer" value="${model.areCustomer }" />
	<div class="header">
		<h2>
			&nbsp;&nbsp;基本信息<span><font color="red">（* 为必填项）</font> </span>
		</h2>
	</div>

	<table class=" form-table">
		<tbody>

			<tr>
				<td class="td1">账号：</td>
				<td class="td2"><form:input path="name" maxlength="150"
						cssClass="" />
					<form:hidden path="enable" value="true" /></td>

			</tr>

			<tr>
				<td class="td1">姓名：</td>
				<td class="td2"><form:input path="fullname" maxlength="150"
						cssClass="required" /></td>


			</tr>

			<tr>
				<td class="td1">性别：</td>
				<td class="td2"><form:radiobuttons path="gender" items="${sex}"
						itemLabel="name" itemValue="name" />
				</td>
			</tr>



			<tr>
				<td class="td1">部门：</td>
				<td class="td2" colspan="3"><form:hidden path="appDepartmentId" />
					<isperp:treeSelector expandAllNode="false"
						id="selectParentDepartment"
						afterSelected="afterSelectDept(ids,names,treeNode)"
						treenodeCreateUrl="app/department/edit" onlySelectLeaf="false"
						autocompleteUrl="app/department/list" afterSelectEmpty="clear();"
						 displayValueCssClass="isExists required"
						url="app/department/getDeptTree?type=customer" valueControlId="appDepartmentId"
						name="departmentTreenodeNamePath" displayValue="${deptName}"></isperp:treeSelector>
					</td>
			</tr>
			
			<tr>

				<td class="td1">所属客户：</td>
				<td class="td2" colspan="3"><form:input path="customerId"
						style="display:none" /> <isperp:listSelector autocomplete="true"
						id="customerSelector" 
						displayColumn="name" name="customerName"
						url="customer/customer/list"
						
						autocompleteDisplay="item.data[o.displayColumn]"
						autocompleteUrl="customer/customer/autocompleteList"
						valueColumn="id" valueControlId="customerId"
						displayValue="${model.customerName }"
						displayValueCssStyle="width:142px" displayValueCssClass="">
						<isperp:column name="id" title="id" hidden="true"></isperp:column>
						<isperp:column name="code" title="编号" width="80">
						</isperp:column>
						<isperp:column name="name" title="客户名称" width="150">
						</isperp:column>
						<isperp:column name="area" title="地区" width="80">
						</isperp:column>
						<isperp:column name="linkman" title="联系人" width="80">
						</isperp:column>
						<isperp:column name="linktel" title="联系电话" width="80">
						</isperp:column>

					</isperp:listSelector>
					</td>
			</tr>
			
			<tr>
				<td class="td1">职务：</td>
				<td class="td2"><form:input path="title" maxlength="50"
						cssClass="" /></td>
			</tr>

			<tr>
				<td class="td1">类型：</td>
				<td class="td2"><form:radiobuttons path="type" items="${type}"
						itemLabel="name" itemValue="name" cssClass="" /></td>
			</tr>
		</tbody>
	</table>
	<div class="header">
		<h2>&nbsp;&nbsp;联系方式</h2>
	</div>
	<table class=" form-table">
		<tbody>
			<tr>
				<td class="td1">邮件：</td>
				<td class="td2"><form:input path="email" cssClass=" email"
						maxlength="100" cssStyle="width:80%" />
				</td>

			</tr>
			<tr>
				<td class="td1">手机：</td>
				<td class="td2"><form:input path="mobile" cssClass="required"
						cssStyle="width:80%" maxlength="100" /></td>

			</tr>
			<tr>
				<td class="td1">电话：</td>
				<td class="td2"><form:input path="tel" maxlength="100"
						cssStyle="width:80%" /></td>

			</tr>
			<tr>
				<td class="td1">联系地址：</td>
				<td class="td2"><form:input path="address" maxlength="200"
						cssStyle="width:80%" /></td>

			</tr>

		</tbody>
	</table>
</form:form>

<jsp:include page="wechatInfo.jsp"></jsp:include>
<script type="text/javascript">

   $(function(){
      var editMode='${editMode}';
      if(editMode=="false")
      {
        $("#areCustomer").val("1");
      }
   });


   function afterSelectDept(ids, names, treeNode) {
		$.ajax({
			url : 'customer/customer/getCustomerByRelateDeptId?deptId=' + ids,
			success : function(data) {
				var cusName = data.name;
				var cusId = data.id;
				$("#customerId").val(cusId);
				$("#customerSelector").val(cusName);
			}
		});
	}

   function createCustomer() {
		isperp.openDialog({
			contentUrl : "customer/customer/edit",
			windowSize:"normal",
			id:"customerCiDiglog",
			title:"新增"
		});
	}

	function sumbitCusUserForm(callback) {
		isperp.submitForm({
			formId : "cusUserForm",
			success : function() {
				callback($("#id").val());

			}
		});
	}
	
	function clear()
	{
	  $("#appDepartmentId").val("");
	  $("#customerId").val("");
	}
	
	function createAfterSelectCustomer(id,name)
	{
	  $("#customerId").val(id);
	  $("#customerSelector").val(name);
	  $.ajax({
	  url:'app/department/list?op=eq&term='+name,
	  success:function(data){
	    if(data.content.length==1)
	    {
	      $("#appDepartmentId").val(data.content[0].id);
	      $("#selectParentDepartment").val(data.content[0].treenodeNamePath);
	    }
	  }
	  })
	}

	$.validator.addMethod("isExists", function(value, element) {
	    var appDepartmentId=$("#appDepartmentId").val();
		if(appDepartmentId=="")
		  return false;
		else 
		  return true;
	}, "请选择有效的客户");
</script>